import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n('common');

const { createConfirm } = useMessage();

enum Api {
  list = '/assetinfo/assetInfo/list',
  save = '/assetinfo/assetInfo/add',
  edit = '/assetinfo/assetInfo/edit',
  deleteOne = '/assetinfo/assetInfo/delete',
  deleteBatch = '/assetinfo/assetInfo/deleteBatch',
  importExcel = '/assetinfo/assetInfo/importExcel',
  exportXls = '/assetinfo/assetInfo/exportXls',
  updateUseState = '/assetinfo/assetInfo/updateUseState',
  outBoundAssetByIds = '/assetinfo/assetInfo/outBoundAssetByIds',
  inBoundAssetByIds = '/assetinfo/assetInfo/inBoundAssetByIds',
  transferRecords = '/transferrecords/transferRecords/queryById',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: t('batchDelTitle'),
    content: t('batchDelTip'),

    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};
export const outBoundAssetByIds = (params) => {
  return defHttp.get({ url: Api.outBoundAssetByIds, params });
};
export const inBoundAssetByIds = (params) => {
  return defHttp.get({ url: Api.inBoundAssetByIds, params });
};
export const transferRecords = (params) => {
  return defHttp.get({ url: Api.transferRecords, params });
};
